$(document).ready(function(){
	var pageurl = $('#service_baseurl').attr('data-url').trim();
	window.pageurl = pageurl;
	var $errorDialog = $("<div></div>").hide().appendTo("body");
	$errorDialog.show().window({
		title : '服务器异常提示',
		width : 650,
		height : 450,
		top : 30,
		closed : true,
		minimizable : false,
		collapsible : false,
		onClose : function() {
			$errorDialog.window("body").html('');
		}
	});
	$.ajaxSetup({
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			if(XMLHttpRequest.readyState==4) {
				if(XMLHttpRequest.status==402 || XMLHttpRequest.status==302) {
					$.messager.alert('系统提示','请重新登录','warning',function(){
						window.parent.location = pageurl+'/system_login';
					});
				} else if(XMLHttpRequest.status==403) {
					$changedpassworddialog.dialog("open");
				} else if(XMLHttpRequest.status==500) {
					$errorDialog.window("open");
					$errorDialog.window("body").html(XMLHttpRequest.responseText);
				} else if(XMLHttpRequest.statusText=='error') {
					$.messager.alert('系统提示','请重新登录','warning',function(){
						window.parent.location = pageurl+'/system_login';
					});
				} 
			} else if(XMLHttpRequest.statusText=='error') {
				$.messager.alert('系统提示','请重新登录','warning',function(){
					window.parent.location = pageurl+'/system_login';
				});
			} 
		}
	});
	$.extend($.fn.datagrid.defaults, {
		onLoadError : function(XMLHttpRequest, textStatus, errorThrown) {
			if(XMLHttpRequest.readyState==4) {
				if(XMLHttpRequest.status==402 || XMLHttpRequest.status==302) {
					$.messager.alert('系统提示','系统超时，请重新登录','warning',function(){
						window.parent.location = pageurl+'/system_login';
					});
				} if(XMLHttpRequest.status==500) {
					$errorDialog.window("open");
					$errorDialog.window("body").html(XMLHttpRequest.responseText);
				} else if(XMLHttpRequest.statusText=='error') {
					$.messager.alert('系统提示','请重新登录','warning',function(){
						window.parent.location = pageurl+'/system_login';
					});
				} 
			} else if(XMLHttpRequest.statusText=='error') {
				$.messager.alert('系统提示','请重新登录','warning',function(){
					window.parent.location = pageurl+'/system_login';
				});
			} 
		}
	});
});